<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>商品列表</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<link type="text/css" rel="stylesheet" href="statics/css/style.css" />


<script type="text/javascript"
	src="/EasyBuy/statics/js/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../../statics/js/menu.js"></script>
<script type="text/javascript" src="../../statics/js/select.js"></script>
</head>

<body>
	<%@ include file="../../common/header.jsp" %>
	<%@ include file="../../common/backendHeader.jsp"%>
	
	<c:choose>
		<c:when test="${empty applicationScope.type }">
			<% 	request.getRequestDispatcher("../../UserServlet?opr=type&href=ProductList&href1=product").forward(request, response); %>
		</c:when>
		<c:otherwise>
			<c:if test="${applicationScope.type==1 }">
  				<%@ include file="../../common/sideMamber.jsp" %> 
			</c:if>
			<c:if test="${applicationScope.type==0 }">
				<%@ include file="../../common/sideUser.jsp" %> 
			</c:if>
		</c:otherwise>
	 </c:choose>
	
	
		<div class="m_right">
			<p></p>
			<div class="mem_tit">商品列表</div>
			<p style="padding-left:880px"><a href="/EasyBuy/backend/product/AddProduct.jsp"  id="add" name="add">商品上架</a></p>
			<table border="0" class="order_tab" id="order_tab"
				style="width:930px; text-align:center; margin-bottom:30px;"
				cellspacing="0" cellpadding="0">
				
			</table>
		</div>
	<%@ include file="../../common/footer.jsp"%>
	<script type="text/javascript"
		src="/EasyBuy/statics/js/jquery-1.4.2.min.js"></script>
	<script type="text/javascript">
    	$(document).ready(function(){
    		//选择商品分页
  		function selectAll(currPageNotransmit){	
  			var ur;
  			if(currPageNotransmit==""||currPageNotransmit==null||currPageNotransmit.length==0){
  				ur="opr=productList";
  			}else{
  				ur="opr=productList&pageIndex="+currPageNotransmit;
  			}
  			$.getJSON("CommodityInformationServlet",ur,selectCallBack);
  		}
  		//回调函数
  		function selectCallBack(data){
  			$("#order_tab").html("");
  			$("#order_tab").append("<tr><td width='20%'>商品名称</td><td width='25%'>商品图片</td><td width='15%'>库存</td><td width='25%'>价格</td><td width='15%' colspan='2'>操作</td></tr>");
  			for ( var i = 0; i < data.productlist.length; i++) {
    				var s = data.productlist[i];
					$("#order_tab").append("<tr><td>"+s.name

				+"</td><td><img src='/EasyBuy/statics/images/"+s.fileName+"' width='100px' height='90px' /></td><td>"+s.stock

				+"</td><td>"+s.price+"</td><td><a href='CommodityInformationServlet?opr=productIdList&id="+s.id+"'>修改</a></td>"+
				"<td><a class='shan' name='"+s.id+"'>删除</a></td></tr>");
			}
			$("#order_tab").append("<tr><td colspan='6'><a class='shou'>首页</a><a class='shang'>上一页</a><a class='xia'>下一页</a><a class='mo'>尾页</a></td></tr>");
  			$(".shou").click(function(){//首页
  				selectAll();
  			});
  			$(".shang").click(function(){//上一页
  				selectAll(data.currPageNo-1);
  			});
  			$(".xia").click(function(){//下一页
  				selectAll(data.currPageNo+1);
  			});
  			$(".mo").click(function(){//最后一页
  				selectAll(data.totalCount);
  			});
  			$(".shan").click(function(){
  				var str=confirm("确定要删除该商品么？");
  				if(str==true){
  					var id=$(this).attr("name");
  					$.getJSON("CommodityInformationServlet","opr=productDel&id="+id,callBack);
  					function callBack(data){
  						if(data==1){
  							alert("删除成功！");
  							selectAll();
  						}else{
  							alert("删除失败！");
  							selectAll();
  						}
  					}
  				}else{
  					alert("已经取消删除！");
  					selectAll();
  				}
  			});
  		};
  		selectAll();
  		});
    </script>
</body>
</html>
